package com.happyhome.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.happyhome.constants.ComUnitName;
import com.happyhome.constants.RecordStatus;
import com.happyhome.datamodel.Province;
import com.happyhome.datamodel.QProvince;
import com.mysema.query.jpa.JPQLQuery;
import com.mysema.query.jpa.impl.JPAQuery;
import com.trg.dao.jpa.GenericDAOImpl;

@Repository
public class ProvinceDaoImpl extends GenericDAOImpl<Province, Long> implements ProvinceDao{
	
	@SuppressWarnings("unused")
	private static final Logger LOGGER = LoggerFactory.getLogger(ProvinceDaoImpl.class);
	
	@Override
	@PersistenceContext(unitName = ComUnitName.COM_UNIT)
	public void setEntityManager(EntityManager entityManager) {
		super.setEntityManager(entityManager);
	}

	@Override
	public List<Province> getAllProvinces() {
		JPQLQuery query = new JPAQuery(em());
		
		QProvince province = QProvince.province;
		
		query.from(province).where(province.status.eq(RecordStatus.TRUE));
		
		List<Province> provinces = query.list(province);
		return provinces;
	}
    
}
